﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace aaaaa
{
    class TPSCamera:BasicCamera
    {
        Vector3 playerDistance;
        /// <summary>
        /// Representa o quão distante a câmera está do jogador (para "trás" e para "cima")
        /// </summary>
        public Vector3 PlayerDistance { get { return playerDistance; } set { playerDistance = value; } }

        Vector3 targetDistance;
        /// <summary>
        /// Representa o quão distante o alvo da câmera está do jogador (para "cima")
        /// </summary>
        public Vector3 TargetDistance { get { return targetDistance; } set { targetDistance = value; } }

        Light light;
        public TPSCamera():base()
        {
            PlayerDistance = new Vector3(0, 10, -15);
            TargetDistance = new Vector3(0, 5, 0);
            //light = new Light(Light.Type.TwoDirections);
            
        }
        public override void Update(GameTime gameTime)
        {
        }

        public void Update(GameTime gameTime, float playerRotationAngle, Vector3 playerPosition)
        {
            Matrix rotationMatrix = Matrix.CreateRotationY(MathHelper.ToRadians(playerRotationAngle));

            Vector3 correctedDistance = Vector3.Transform(PlayerDistance, rotationMatrix);
            Vector3 correctedTarget = Vector3.Transform(TargetDistance, rotationMatrix);

            Position = playerPosition + correctedDistance;
            Target = playerPosition + correctedTarget;

            ViewMatrix = Matrix.CreateLookAt(Position, Target, Orientation);

            ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.ToRadians(ApertureAngle),
                ScreenRatio,
                NearPlane,
                FarPlane);
            base.Update();
        }
        public void Update(GameTime gameTime, bool retro)
        {

        }
    }
}
